package api

import (
	"errors"

	"gitee.com/wosylf/ltool/ssl/model"
)

type AuthorizationService service

// Get Gets an authorization.
func (c *AuthorizationService) Get(authzURL string) (*model.Authorization, error) {
	if authzURL == "" {
		return nil, errors.New("authorization[get]: empty URL")
	}

	var authz model.Authorization
	_, err := c.core.postAsGet(authzURL, &authz)
	//fmt.Println("验证的时间戳", time.Now().UnixMicro())
	//fmt.Printf("\n----"+authzURL+"-----正在使用(c *AuthorizationService) Get方法请求---- %+v", authz)
	if err != nil {
		return nil, err
	}
	return &authz, nil
}

// Deactivate Deactivates an authorization.
func (c *AuthorizationService) Deactivate(authzURL string) error {
	if authzURL == "" {
		return errors.New("authorization[deactivate]: empty URL")
	}

	var disabledAuth model.Authorization
	_, err := c.core.Post(authzURL, model.Authorization{Status: model.StatusDeactivated}, &disabledAuth)
	return err
}
